const app = getApp()

Page({
    data: {

    },
    toSearch() {
        wx.navigateTo({
            url: '/pages/index/search/search',
        })
    },
    onShow() {
        this.getLbt();
        this.getSpots()
        this.getType()
    },
    //获取资讯(轮播图设置)
    getLbt() {
        var that = this;
        wx.request({
          url: app.globalData.baseUrl + 'api/lbt/v1/getAll',
          method:'POST',
          success:function(res){
            that.setData({
                banner : res.data.data
            })
          }
        })
    },
    /**
     * 获取景点类别
     */
    getType() {
        var that =this;
        wx.request({
            url: app.globalData.baseUrl + 'api/jdlx/v1/wx/getJdlx',
            method:'POST',
            data:{},
            success:function(res){
              that.setData({
                types : res.data
              })
            }
          })
        // wx.cloud.database().collection("travel_types").get()
        //     .then(res => {
        //         console.log(res.data)

        //         this.setData({
        //             types: res.data
        //         })

        //     })
    },

    getSpots() {
        var that =this;
        wx.request({
            url: app.globalData.baseUrl + 'api/spots/v1/wx/getAll',
            method:'POST',
            data:{},
            success:function(res){
              that.setData({
                spotList : res.data
              })
            }
          })
        // wx.cloud.database().collection('travel_spots').get()
        //     .then(res => {

        //         console.log(res)
        //         this.setData({
        //             spotList: res.data
        //         })
        //     })

    },
    toSpotDetail(event) {
      var that =this;
      console.log(event,"event")
      // cJdlxId  //类型id
      //cJdlxId
      // console.log(this.data.spotList,"spotListspotList")
      
      // const filteredSpotList = this.data.spotList.filter(item => {
      //   return item.cJdlxId === event.detail.name;
      // });
      // this.data.spotList=  filteredSpotList
      wx.request({
        url: app.globalData.baseUrl + 'api/spots/v1/wx/getAll',
        method:'POST',
        data:{
            jdlxId: event.detail.name
        },
        success:function(res){
          that.setData({
            spotList : res.data
          })
        }
      })

        // wx.navigateTo({
        //     url: '/pages/index/spotList/spotList?typeId=' + event.detail.name,
        // })
    },


    toDetail(event) {
        if (!app.globalData.userInfo) {
            wx.switchTab({
                url: '/pages/me/me',
                success() {
                    wx.showToast({
                        icon: 'error',
                        title: '请登录',
                    })
                }
            })
            return
        }
        wx.navigateTo({
            url: '/pages/index/spotDetail/spotDetail?cId=' + event.currentTarget.dataset.id,
        })
    },
    // toSearch(){
    //   wx.navigateTo({
    //     url: '../../pages/index/search/search',
    //   })
    // },
    toBannerDetail(event) {

        console.log(event.currentTarget.dataset.id)

        wx.navigateTo({
            url: '/pages/index/bannerDetail/bannerDetail?id=' + event.currentTarget.dataset.id,
        })

    },
})